package com.saltedfish.tool.dialog;

import android.app.Activity;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.saltedfish.tool.R;
import com.saltedfish.tool.model.User;
import com.saltedfish.tool.util.SharePreferceUtils;

import butterknife.BindView;
import cn.droidlover.xdroidmvp.base.SimpleListener;
import cn.droidlover.xdroidmvp.imageloader.ILFactory;
import cn.droidlover.xdroidmvp.popwindow.DialogHelper;
import cn.droidlover.xdroidmvp.util.AppUtil;
import cn.droidlover.xdroidmvp.view.XCRoundRectImageView;

public class UIUserDialog extends DialogHelper {

    @BindView(R.id.rel_suggest)
    RelativeLayout rel_suggest;

    @BindView(R.id.tvBack)
    TextView tvBack;

    @BindView(R.id.tvUserId)
    TextView tvUserId;

    @BindView(R.id.tvNumId)
    TextView tvNumId;

    @BindView(R.id.rel_logout)
    RelativeLayout rel_logout;

    @BindView(R.id.iv_imageLogo)
    XCRoundRectImageView iv_imageLogo;

    @BindView(R.id.tv_user_service)
    TextView tv_user_service;

    @BindView(R.id.tv_user_sercret)
    TextView tv_user_sercret;

    @BindView(R.id.tv_version)
    TextView tv_version;


    @BindView(R.id.outcancel)
    RelativeLayout outcancel;

    public UIUserDialog(Activity context) {
        super(context, R.style.AlertDialogStyle);
        this.mContext = context;

        setFullWidthScreen();
        setGravity(Gravity.BOTTOM);
        setAnimSet(R.style.popBottomPopAnim);

    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_ui_user;
    }

    @Override
    protected void initView() {

        tvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });

        rel_logout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener != null) {
                    listener.onClick("rel_logout");
                }
                dismiss();
            }
        });

        rel_suggest.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener != null) {
                    listener.onClick("rel_suggest");
                }
            }
        });


        tv_user_service.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener != null) {
                    listener.onClick("userService");
                }
            }
        });


        tv_user_sercret.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener != null) {
                    listener.onClick("userSecret");
                }
            }
        });

        outcancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener != null) {
                    listener.onClick("outCancel");
                }
            }
        });

    }


    @Override
    protected void initData() {
        String userID  = SharePreferceUtils.getString(User.USER_REAL_NAME);
        String USER_IMAGE  = SharePreferceUtils.getString(User.USER_IMAGE);
        String saltFishNo  = SharePreferceUtils.getString(User.saltFishNo);

        tvUserId.setText(userID);
        tvNumId.setText(saltFishNo);
        ILFactory.getLoader().loadCircle(USER_IMAGE, iv_imageLogo, null);

        String version = AppUtil.getVersionName(mContext);
        tv_version.setText("版本号："+version);


    }


    @Override
    protected void dialogDismiss() {
        dismiss();
    }

    @Override
    public void dismiss() {
        mContext.getWindow().setStatusBarColor(mContext.getResources().getColor(R.color.color_white));
        super.dismiss();

    }

}
